<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>MiXiM: D:/Projects/MiXiM/extsrc/mixim/src/modules/phy/RadioUWBIR.h Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>


</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">MiXiM
   &#160;<span id="projectnumber">2.3</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('a00479.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">RadioUWBIR.h</div>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> * RadioUWBIR.h</span>
<a name="l00003"></a>00003 <span class="comment"> * Author: Jerome Rousselot &lt;jerome.rousselot@csem.ch&gt;</span>
<a name="l00004"></a>00004 <span class="comment"> * Copyright: (C) 2008-2010 Centre Suisse d&#39;Electronique et Microtechnique (CSEM) SA</span>
<a name="l00005"></a>00005 <span class="comment"> *              Wireless Embedded Systems</span>
<a name="l00006"></a>00006 <span class="comment"> *              Jaquet-Droz 1, CH-2002 Neuchatel, Switzerland.</span>
<a name="l00007"></a>00007 <span class="comment"> */</span>
<a name="l00008"></a>00008 
<a name="l00009"></a>00009 <span class="preprocessor">#ifndef UWBIRRADIO_H_</span>
<a name="l00010"></a>00010 <span class="preprocessor"></span><span class="preprocessor">#define UWBIRRADIO_H_</span>
<a name="l00011"></a>00011 <span class="preprocessor"></span>
<a name="l00012"></a>00012 <span class="preprocessor">#include &quot;MiXiMDefs.h&quot;</span>
<a name="l00013"></a>00013 <span class="preprocessor">#include &quot;PhyUtils.h&quot;</span>
<a name="l00014"></a>00014 <span class="preprocessor">#include &quot;PhyLayerUWBIR.h&quot;</span>
<a name="l00015"></a>00015 
<a name="l00029"></a><a class="code" href="a00183.html">00029</a> <span class="keyword">class </span>MIXIM_API <a class="code" href="a00183.html" title="This class extends the basic radio model.">RadioUWBIR</a>: <span class="keyword">public</span> <a class="code" href="a00141.html" title="The class that represents the Radio as a state machine.">MiximRadio</a> {
<a name="l00030"></a>00030   <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="a00175.html" title="Physical layer that models an Ultra Wideband Impulse Radio wireless communication system...">PhyLayerUWBIR</a>;
<a name="l00031"></a>00031 
<a name="l00032"></a>00032 <span class="keyword">public</span>:
<a name="l00033"></a>00033 
<a name="l00034"></a>00034   <span class="keyword">enum</span> UWBIRRadioStates {
<a name="l00035"></a>00035     <span class="comment">/* receiving state*/</span>
<a name="l00036"></a>00036      SYNC = <a class="code" href="a00141.html#a5d69aacb1cf6a57827f07224219fccb7ac1eb11ffe24036a5e7c1a07035db2bba" title="No real radio state just a counter constant for the amount of states.">MiximRadio::NUM_RADIO_STATES</a>,
<a name="l00037"></a>00037      UWBIR_NUM_RADIO_STATES
<a name="l00038"></a>00038   };
<a name="l00039"></a>00039 
<a name="l00040"></a>00040   <span class="comment">/* Static factory method (see Radio class in PhyUtils.h) */</span>
<a name="l00041"></a>00041   <span class="keyword">static</span> <a class="code" href="a00183.html" title="This class extends the basic radio model.">RadioUWBIR</a>* createNewUWBIRRadio(<span class="keywordtype">bool</span>                       <a class="code" href="a00029.html#a71f6c8e91a8f597a5d213b30c64b0cf8" title="Stores if tracking of statistics (esp. cOutvectors) is enabled.">recordStats</a>,
<a name="l00042"></a>00042                                          <span class="keywordtype">int</span>                        initialState,
<a name="l00043"></a>00043                                          Argument::mapped_type_cref minAtt       = <a class="code" href="a00013.html#a657d962a1b965814e6b2eecb07f03e80" title="One value of a Argument value.">Argument::MappedOne</a>,
<a name="l00044"></a>00044                                          Argument::mapped_type_cref maxAtt       = <a class="code" href="a00013.html#a8523627cdc70492e5e0935b9a3a78cc4" title="Zero value of a Argument value.">Argument::MappedZero</a>)
<a name="l00045"></a>00045   {
<a name="l00046"></a>00046     <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="a00183.html" title="This class extends the basic radio model.">RadioUWBIR</a>(RadioUWBIR::UWBIR_NUM_RADIO_STATES,
<a name="l00047"></a>00047              recordStats,
<a name="l00048"></a>00048              initialState,
<a name="l00049"></a>00049              minAtt, maxAtt);
<a name="l00050"></a>00050   }
<a name="l00051"></a>00051 
<a name="l00057"></a><a class="code" href="a00183.html#a4fcf2fff34e2a9d289028ebe13b6ada1">00057</a>   <span class="keyword">virtual</span> simtime_t <a class="code" href="a00183.html#a4fcf2fff34e2a9d289028ebe13b6ada1" title="This switchTo method only accepts three states to switch to: reception, transmission and sleep...">switchTo</a>(<span class="keywordtype">int</span> newState, simtime_t_cref now) {
<a name="l00058"></a>00058     <span class="comment">// state must be one of sleep, receive or transmit (not sync)</span>
<a name="l00059"></a>00059     <span class="comment">//assert(newState != Radio::SYNC);</span>
<a name="l00060"></a>00060     <span class="keywordflow">if</span>(newState == state || (newState == <a class="code" href="a00141.html#a5d69aacb1cf6a57827f07224219fccb7a2c1aea88fe8363141c138da817461953" title="receiving state">RadioUWBIR::RX</a> &amp;&amp; state == RadioUWBIR::SYNC)) {
<a name="l00061"></a>00061       <span class="keywordflow">return</span> -1; <span class="comment">// nothing to do</span>
<a name="l00062"></a>00062     } <span class="keywordflow">else</span> {
<a name="l00063"></a>00063       <span class="keywordflow">if</span>(newState == <a class="code" href="a00141.html#a5d69aacb1cf6a57827f07224219fccb7a2c1aea88fe8363141c138da817461953" title="receiving state">RadioUWBIR::RX</a>) {
<a name="l00064"></a>00064         <span class="comment">// prevent entering &quot;frame reception&quot; immediately</span>
<a name="l00065"></a>00065         newState = RadioUWBIR::SYNC;
<a name="l00066"></a>00066       }
<a name="l00067"></a>00067       <span class="keywordflow">return</span> reallySwitchTo(newState, now);
<a name="l00068"></a>00068     }
<a name="l00069"></a>00069   }
<a name="l00070"></a>00070 
<a name="l00071"></a>00071   <span class="keyword">virtual</span> simtime_t reallySwitchTo(<span class="keywordtype">int</span> newState, simtime_t_cref now) {
<a name="l00072"></a>00072     <span class="comment">// set the nextState to the newState and the current state to SWITCHING</span>
<a name="l00073"></a>00073     nextState = newState;
<a name="l00074"></a>00074     <span class="keywordtype">int</span> lastState = <a class="code" href="a00141.html#aa735fae8f7e81f7b3a56b651401c79d0" title="The current state the radio is in.">state</a>;
<a name="l00075"></a>00075     state = <a class="code" href="a00141.html#a5d69aacb1cf6a57827f07224219fccb7adb16d903144a4b227138692871b6edde" title="switching between two states">RadioUWBIR::SWITCHING</a>;
<a name="l00076"></a>00076     radioStates.record(state);
<a name="l00077"></a>00077     <span class="comment">// make entry to RSAM</span>
<a name="l00078"></a>00078     <a class="code" href="a00141.html#aef828c78b65e04eb308929880d2ac8f7" title="responsible for making entries to the RSAM">makeRSAMEntry</a>(now, state);
<a name="l00079"></a>00079 
<a name="l00080"></a>00080     <span class="comment">// return matching entry from the switch times matrix</span>
<a name="l00081"></a>00081     <span class="keywordflow">return</span> swTimes[lastState][<a class="code" href="a00141.html#ae774d34df7824189236e45fd71b32f29" title="The state the radio is currently switching to.">nextState</a>];
<a name="l00082"></a>00082   }
<a name="l00083"></a>00083 
<a name="l00084"></a>00084 <span class="keyword">protected</span>:
<a name="l00085"></a>00085 
<a name="l00086"></a>00086   <a class="code" href="a00183.html" title="This class extends the basic radio model.">RadioUWBIR</a>(<span class="keywordtype">int</span> numRadioStates,<span class="keywordtype">bool</span> recordStats, <span class="keywordtype">int</span> initialState, Argument::mapped_type_cref minAtt = <a class="code" href="a00013.html#a657d962a1b965814e6b2eecb07f03e80" title="One value of a Argument value.">Argument::MappedOne</a>, Argument::mapped_type_cref maxAtt = <a class="code" href="a00013.html#a8523627cdc70492e5e0935b9a3a78cc4" title="Zero value of a Argument value.">Argument::MappedZero</a>)
<a name="l00087"></a>00087   :<a class="code" href="a00141.html" title="The class that represents the Radio as a state machine.">MiximRadio</a>(numRadioStates, recordStats, initialState, minAtt, maxAtt) {  }
<a name="l00088"></a>00088 
<a name="l00089"></a><a class="code" href="a00183.html#a4b53bfa722dbe40dd1a46ddc39c90a81">00089</a>   <span class="keyword">virtual</span> Argument::mapped_type_cref <a class="code" href="a00141.html#a8fb94b6085e7ee54877407a111755fc1" title="maps RadioState to attenuation, the Radios receiving characteristic">mapStateToAtt</a>(<span class="keywordtype">int</span> state)
<a name="l00090"></a>00090   {
<a name="l00091"></a>00091     <span class="keywordflow">if</span> (state == <a class="code" href="a00141.html#a5d69aacb1cf6a57827f07224219fccb7a2c1aea88fe8363141c138da817461953" title="receiving state">RadioUWBIR::RX</a> || state == RadioUWBIR::SYNC) {
<a name="l00092"></a>00092       <span class="keywordflow">return</span> <a class="code" href="a00141.html#a891a34f0c4280d790bd6d97db8270977" title="Constant to store the minimum attenuation for a Radio instance.">minAtt</a>;
<a name="l00093"></a>00093     } <span class="keywordflow">else</span> {
<a name="l00094"></a>00094       <span class="keywordflow">return</span> <a class="code" href="a00141.html#a26aaf48126840634a094e8223d121259" title="Constant to store the maximum attenuation for a Radio instance.">maxAtt</a>;
<a name="l00095"></a>00095     }
<a name="l00096"></a>00096   }
<a name="l00097"></a>00097 
<a name="l00098"></a>00098 <span class="keyword">private</span>:
<a name="l00103"></a><a class="code" href="a00183.html#a2fe9963465ed09e02428c4949a85d56b">00103</a>   <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="a00183.html#a2fe9963465ed09e02428c4949a85d56b" title="Called by the decider through the phy layer to announce that the radio has locked on a frame and is a...">startReceivingFrame</a>(simtime_t_cref now) {
<a name="l00104"></a>00104     assert(state == RadioUWBIR::SYNC);
<a name="l00105"></a>00105     state = <a class="code" href="a00141.html#a5d69aacb1cf6a57827f07224219fccb7adb16d903144a4b227138692871b6edde" title="switching between two states">RadioUWBIR::SWITCHING</a>;
<a name="l00106"></a>00106     nextState = <a class="code" href="a00141.html#a5d69aacb1cf6a57827f07224219fccb7a2c1aea88fe8363141c138da817461953" title="receiving state">RadioUWBIR::RX</a>;
<a name="l00107"></a>00107     <a class="code" href="a00141.html#ae9820653aa09c297148210c1de27a2e1" title="called by PhyLayer when duration-time for the current switching process is up">endSwitch</a>(now);
<a name="l00108"></a>00108   }
<a name="l00114"></a><a class="code" href="a00183.html#a1cdcafe6ddd11881a67a519f5ca90f82">00114</a>   <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="a00183.html#a1cdcafe6ddd11881a67a519f5ca90f82" title="Called by the decider through the phy layer to announce that the radio has finished receiving a frame...">finishReceivingFrame</a>(simtime_t_cref now) {
<a name="l00115"></a>00115     assert(state == <a class="code" href="a00141.html#a5d69aacb1cf6a57827f07224219fccb7a2c1aea88fe8363141c138da817461953" title="receiving state">RadioUWBIR::RX</a>);
<a name="l00116"></a>00116     state = <a class="code" href="a00141.html#a5d69aacb1cf6a57827f07224219fccb7adb16d903144a4b227138692871b6edde" title="switching between two states">RadioUWBIR::SWITCHING</a>;
<a name="l00117"></a>00117     nextState = RadioUWBIR::SYNC;
<a name="l00118"></a>00118     <a class="code" href="a00141.html#ae9820653aa09c297148210c1de27a2e1" title="called by PhyLayer when duration-time for the current switching process is up">endSwitch</a>(now);
<a name="l00119"></a>00119   }
<a name="l00120"></a>00120 
<a name="l00121"></a>00121 };
<a name="l00122"></a>00122 
<a name="l00123"></a>00123 <span class="preprocessor">#endif </span><span class="comment">/* UWBIRRADIO_H_ */</span>
</pre></div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><b>RadioUWBIR.h</b>      </li>

    <li class="footer">Generated on Tue Mar 5 2013 21:26:30 for MiXiM by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.5.1 </li>
   </ul>
 </div>


</body>
</html>
